package com.ruoyi.project.dict.lishi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.lishi.domain.CizuLishi;
import com.ruoyi.project.dict.lishi.service.ICizuLishiService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 历史解释Controller
 * 
 * @author shixiangwen
 * @date 2021-04-08
 */
@Controller
@RequestMapping("/dict/lishi")
public class CizuLishiController extends BaseController
{
    private String prefix = "dict/lishi";

    @Autowired
    private ICizuLishiService cizuLishiService;

    @RequiresPermissions("dict:lishi:view")
    @GetMapping()
    public String lishi()
    {
        return prefix + "/lishi";
    }

    /**
     * 查询历史解释列表
     */
    @RequiresPermissions("dict:lishi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CizuLishi cizuLishi)
    {
        startPage();
        List<CizuLishi> list = cizuLishiService.selectCizuLishiList(cizuLishi);
        return getDataTable(list);
    }

    /**
     * 导出历史解释列表
     */
    @RequiresPermissions("dict:lishi:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CizuLishi cizuLishi)
    {
        List<CizuLishi> list = cizuLishiService.selectCizuLishiList(cizuLishi);
        ExcelUtil<CizuLishi> util = new ExcelUtil<CizuLishi>(CizuLishi.class);
        return util.exportExcel(list, "lishi");
    }

    /**
     * 新增历史解释
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史解释
     */
    @RequiresPermissions("dict:lishi:add")
    @Log(title = "历史解释", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CizuLishi cizuLishi)
    {
        return toAjax(cizuLishiService.insertCizuLishi(cizuLishi));
    }

    /**
     * 修改历史解释
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CizuLishi cizuLishi = cizuLishiService.selectCizuLishiById(id);
        mmap.put("cizuLishi", cizuLishi);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史解释
     */
    @RequiresPermissions("dict:lishi:edit")
    @Log(title = "历史解释", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CizuLishi cizuLishi)
    {
        return toAjax(cizuLishiService.updateCizuLishi(cizuLishi));
    }

    /**
     * 删除历史解释
     */
    @RequiresPermissions("dict:lishi:remove")
    @Log(title = "历史解释", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cizuLishiService.deleteCizuLishiByIds(ids));
    }
}
